/**
 * @author gabrielepiva
 */
/* aqStamp v1.0.3 - Converts UNIX time stamps in seconds to human readable format.
   Copyright (C) 2009 Paul Pham <http://aquaron.com/~jquery/aqStamp>

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
(function($){
   $.aqStamp = function($seed,$span) {
      var _now = new Date();
      var _d = Math.ceil(_now.getTime() / 1000) - $seed;
      var _string = '';
      var _t = $.aqStamp.text;

      if (_d < 60) _string = _t.seconds;
      else if (_d < 120) _string = _t.minute;
      else if (_d < 3600) _string = Math.round(_d/60) +' '+ _t.minutes;
      else if (_d < 7200) _string = _t.hour;
      else if (_d < 86400) _string = Math.round(_d/3600) +' '+ _t.hours;
      else if (_d < 172800) _string = _t.day;
      else if (_d < 2678400) _string = Math.round(_d/86400) +' '+ _t.days;
      else if (_d < 5356800) _string = _t.month;
      else if (_d < 31536000) _string = Math.round(_d/2678400) +' '+ _t.months;
      else if (_d < 63072000) _string = _t.year;
      else _string = Math.round(_d/31536000) +' '+ _t.years;
      if ($span) {
         _now = new Date ($seed*1000);
         return '<span title="'+_now.toLocaleString()+'">'+_string + ' ' 
         + _t.ago+'<\/span>';
      }
      return _string + ' ' + _t.ago;
   };
   $.aqStamp.text = {
      seconds: 'pochi secondi',
      minute:  'circa un minuto',
      minutes: 'minuti', 
      hour:    'circa un\'ora',
      hours:   'ore', 
      day:     'circa un giorno',
      days:    'giorni', 
      month:   'circa un mese',
      months:  'mesi', 
      year:    'circa un anno',
      years:   'anni', 
      ago:     'fa'
   };
})(jQuery);